//
//  GCMineHomeHeaderView.m
//  GoldChampion
//
//  Created by Mac on 2018/4/13.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "GCOtherHomeView.h"
@interface GCOtherHomeView()
@property(nonatomic, strong) UIImageView                     *bannerImageView;
@property(nonatomic, strong) UIVisualEffectView                     *visualView;
@property(nonatomic, strong) STLabel                     *titleLable;
@end
@implementation GCOtherHomeView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self configSubView];
    }
    return self;
}
#pragma mark --subView
- (void)configSubView{
    self.height = 190;
    
    self.bannerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 190)];
    self.bannerImageView.image = [UIImage imageNamed:@"17"];
    [self addSubview:self.bannerImageView];
    
    self.visualView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
    self.visualView.frame = CGRectMake(0, 0, UIScreenWidth, [TMUtils navgationBarBootom]);
    self.visualView.alpha = 0;
    [self addSubview:self.visualView];
    
    self.titleLable = [[STLabel alloc] initWithFrame:CGRectMake(0, 0, 200, 44)
                                                text:@"大佬"
                                           textColor:[UIColor whiteColor]
                                                font:18
                                         isSizetoFit:NO
                                       textAlignment:NSTextAlignmentCenter];
    [self addSubview:self.titleLable];
    self.titleLable.centerX = UIScreenWidth/2;
    self.titleLable.bottom = [TMUtils navgationBarBootom];
    __weak typeof(self) weakSelf =  self;
    
    STButton * backButton = [self deflutButtonWithImageName:@"返回"];
    [backButton setClicAction:^(UIButton *sender) {
        if (weakSelf.onSelectedMenuHandle) {
            weakSelf.onSelectedMenuHandle(0);
        }
    }];
    [self addSubview:backButton];
    
    STButton * sixinButton = [self deflutButtonWithImageName:@"消息top"];
    sixinButton.right = UIScreenWidth;
    [sixinButton setClicAction:^(UIButton *sender) {
        if (weakSelf.onSelectedMenuHandle) {
            weakSelf.onSelectedMenuHandle(2);
        }
    }];
    [self addSubview:sixinButton];
    
    
    STButton * shareButton = [self deflutButtonWithImageName:@"分享W"];
    shareButton.right = sixinButton.left;
    [shareButton setClicAction:^(UIButton *sender) {
        if (weakSelf.onSelectedMenuHandle) {
            weakSelf.onSelectedMenuHandle(1);
        }
    }];
    [self addSubview:shareButton];
    

}
- (STButton*)deflutButtonWithImageName:(NSString*)imageName{
    STButton * backButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)
                                                      title:@""
                                                 titleColor:nil
                                                  titleFont:0
                                               cornerRadius:0
                                            backgroundColor:nil
                                            backgroundImage:nil
                                                      image:[UIImage imageNamed:imageName]];
    backButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    backButton.bottom = [TMUtils navgationBarBootom];
    return backButton;
}
#pragma mark --public
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGFloat currentY = scrollView.contentOffset.y;
    NSLog(@"collection 滑动%f",currentY);
    
    // 顶部banner 滑动到 [TMUtils navgationBarBootom] 停止
    if (currentY >= 0) {
        self.bannerImageView.top = -currentY;
        if (self.bannerImageView.bottom < [TMUtils navgationBarBootom]) {
            self.bannerImageView.bottom = [TMUtils navgationBarBootom];
        }
        //高斯模糊 效果
        // 0 ~1,
        CGFloat minAlpha = 0;
        CGFloat maxAlpha = 1;
        CGFloat maxAlphyScrollValue = self.height - [TMUtils navgationBarBootom];
        CGFloat bilie = currentY / maxAlphyScrollValue;
        CGFloat alpha = bilie * (maxAlpha -minAlpha);
        self.visualView.alpha = alpha;
        self.bannerImageView.transform = CGAffineTransformIdentity;
    }else{
        self.visualView.alpha = 0;//隐藏
        CGFloat imageHeight = 2 * ABS(currentY) + self.height;
        CGFloat bili = imageHeight / self.height;
        self.bannerImageView.width = self.width * bili;
        self.bannerImageView.height = self.height * bili;
        self.bannerImageView.centerX = UIScreenWidth / 2;
        self.bannerImageView.centerY = self.height / 2;
    }
}
@end

